<template>
  <div>
    <el-checkbox-group v-model="checkList">
        <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{item.name}}</el-checkbox>
    </el-checkbox-group>
    
    <div style="text-align: right">
      <el-button @click="quxiao">取消</el-button>
      <el-button type="primary" @click="queding">确定</el-button>
    </div>
  </div>
</template>

<script>
    import { getRoles } from '@/api/settings'
    import {getuserhead} from '@/api/user'
    import {assignROles} from '@/api/employees'
export default {
    props:{
      id:{
      type:String,
      required:true
    }
    },
    data() {
        return {
            checkList:[],
            list:[],
        }
    },
created(){
 this.loadRoles()
},
 methods:{
    // 更新数据
    async queding(){
    const res = await assignROles({id:this.id,roleIds:this.checkList})
    console.log(res);
    this.$emit('success')
    },
    // 获取户数
    async loadRoles(){
      try {
        const res = await getRoles({page:1,pagesize:100})
        console.log('getRoles', res)
        this.list = res.data.rows
        // 保存数据 
        const info = await getuserhead(this.id)
        console.log(info);
        this.checkList = info.data.roleIds
      } catch (err) {
        console.log('getRoles', err)
      }
    },
    // 取消按钮
  quxiao(){
   this.$emit('success')
}
}
}
</script>

<style>

</style>